package biz.ezcom.servlet.listener.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SubmitServlet extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
//		System.out.println("SubmitServlet.doPost() start");
		String username = request.getParameter("username");
		String password = request.getParameter("password");

		
//		System.out.println("ServletRequestAttributeListener");
//		System.out.println("request.setAttribute() start");
//		request.setAttribute("setAttribute", "setAttribute");
//		System.out.println("request.setAttribute() end");
		
//		System.out.println();
//		System.out.println("request.setAttribute() 第二次start");
//		request.setAttribute("setAttribute", "setAttribute");
//		System.out.println("request.setAttribute() 第二次end");

//		System.out.println();
//		System.out.println("request.removeAttribute() start");
//		request.removeAttribute("setAttribute");
//		System.out.println("request.removeAttribute() end");

		
//		System.out.println("HttpSessionAttributeListener");
//		HttpSession session = request.getSession();
//		System.out.println("session.setAttribute() 第1次 start");
//		session.setAttribute("key", "value1");
//		System.out.println("session.setAttribute() 第1次 end");
//		
//		System.out.println();
//		System.out.println("session.setAttribute() 第2次 start");
//		session.setAttribute("key", "value2");
//		System.out.println("session.setAttribute() 第2次 end");
//		
//		System.out.println();
//		System.out.println("session.removeAttribute() start");
//		session.removeAttribute("key");
//		System.out.println("session.removeAttribute() end");
		
		
		System.out.println("HttpSessionBindingListener");
		System.out.println("HttpSessionActivationListener");
		
		
//		System.out.println("HttpSessionListener");
//		System.out.println("session.invalidate() start");
//		HttpSession session = request.getSession();
//		session.invalidate();
//		System.out.println("session.invalidate() end");

		
//		System.out.println("ServletContextAttributeListener");
//		ServletContext servletContext = request.getSession().getServletContext();
//		System.out.println("servletContext.setAttribute() 第1次 start");
//		servletContext.setAttribute("key", "value");
//		System.out.println("servletContext.setAttribute() 第1次 end");
		
//		System.out.println();
//		System.out.println("servletContext.setAttribute() 第2次 start");
//		servletContext.setAttribute("key", "value");
//		System.out.println("servletContext.setAttribute() 第2次 end");
		
//		System.out.println();
//		System.out.println("servletContext.removeAttribute() start");
//		servletContext.removeAttribute("key");
//		System.out.println("servletContext.removeAttribute() end");
		
		
		System.out.println();
		response.setHeader("Content-Type", "text/html; charset=UTF-8");
		PrintWriter pw = response.getWriter();
		pw.write("username:" + username + "<br />");
		pw.write("password:" + password + "<br />");
	}
}
